<template lang="jade">
div.return-bar
	i.iconfont(@click="back()") &#xe668;
	开通华兴银行存管账户


div.openAccount.detail_top
	strong 请输入您的真实信息，否则会影响您的充值提现
	ul
		li
			label 真实姓名
			input(name="realname",v-model="realname",placeholder="请输入持卡人真实姓名")
		li
			label 身份证号
			input(name="card",v-model="card",placeholder="请输入身份证号码")
	div.btn
		button.m_btn(type="button", @click="doIt()") 下一步

formpage(:url.sync="post_url", :rdata.sync="post_data")
div.homeloading
	loading(:show="show_loading", text="正在加载")
</template>


<script>
import '../../assets/sass/user/index.scss'
import {Api_openAccount, c_is_logined} from '../../config/api'
import FormPage from '../../components/common/form'
import {Loading} from 'vux'
import api from '../../data/api';
export default {

	data () {
		return {
			post_url: '',
			post_data:{},
			show_loading:false,
			realname: '',
			card: '',
			busy:false,
			subForm:null
		}
	},
	components:{
		formpage:FormPage,
		loading:Loading
	},
	methods: {
		getForm(){
			for(var a in this.$children){
				if(this.$children[a].name == 'form')
					this.subForm = this.$children[a];
			}
		},

		async is_login(){
			//console.log('123')
			var res = await api.user.is_Logined();
			if(res.status == false ){
				this.$route.router.go('/login?from='+this.$route.path.substring(1))
			}

		},

		back(){
			//window.history.back();
			this.$route.router.go('/user')
		},

	 	doIt() {
			if(this.realname == '' || this.card == ''){
				alert('请填写完整的信息！')
				return false;
			}
			if(this.busy){
				return false;
			}
			this.$store.dispatch('setShowLoading', true);
			this.busy = true;
			var data = {'card':this.card, 'realname': this.realname}

			this.$http.post(Api_openAccount, data,'').then(function (response) {
					var rs = response.data;
					this.$store.dispatch('setShowLoading', false);

					if(!rs.status){
						alert(rs.msg)
						this.busy = false;
					}else {

						this.getForm();
						this.subForm.show = true
						this.post_url = rs.action_url
						this.post_data.RequestData = rs.RequestData
						this.post_data.transCode = rs.transCode
						this.subForm.submit();


					}
			}, function (response) {

			});
		}
	},
	route: {
		activate ( transition ) {
			transition.next();
			this.is_login();
		}
	}
}
</script>
